import environ
import json
from django.conf import settings
import os
# 初始化环境变量
env = environ.Env()

# 从.env文件读取环境变量（如果存在）
environ.Env.read_env()
print(os.getenv('DB_ENGINE'))
# 获取所有已定义的环境变量（包括Django默认的）
all_env_vars = {
    # 数据库配置
    'DB_ENGINE': env('DB_ENGINE', default=None),
    'DB_NAME': env('DB_NAME', default=None),
    'DB_HOST': env('DB_HOST', default=None),
    'DB_PORT': env('DB_PORT', default=None),
    'DB_USER': env('DB_USER', default=None),
    'DB_PASSWORD': env('DB_PASSWORD', default=None),

    # 客户数据库配置
    'DB_CUSTOMER_ENGINE': env('DB_CUSTOMER_ENGINE', default=None),
    'DB_CUSTOMER_NAME': env('DB_CUSTOMER_NAME', default=None),
    'DB_CUSTOMER_HOST': env('DB_CUSTOMER_HOST', default=None),
    'DB_CUSTOMER_PORT': env('DB_CUSTOMER_PORT', default=None),
    'DB_CUSTOMER_USER': env('DB_CUSTOMER_USER', default=None),
    'DB_CUSTOMER_PASSWORD': env('DB_CUSTOMER_PASSWORD', default=None),

    # Django核心配置
    'DEBUG': env.bool('DEBUG', default=False),
    'SECRET_KEY': env('SECRET_KEY', default=None),
    'ALLOWED_HOSTS': env.list('ALLOWED_HOSTS', default=['*']),

    # 其他可能的环境变量
    'DATABASE_URL': env('DATABASE_URL', default=None),
    'CACHE_URL': env('CACHE_URL', default=None),
}

# 过滤掉None值
filtered_env_vars = {k: v for k, v in all_env_vars.items() if v is not None}

# 以JSON格式打印
print(json.dumps(filtered_env_vars, indent=2, ensure_ascii=False))